#ifndef _M_config_H
#define _M_config_H
#include "util.hpp"
#include <mutex>
#define CONFIG_FILE "./cloud.conf"
namespace tqbcloud
{
    class Config
    {
    private:
        Config()
        {
            tqbcloud::Fileutil f(CONFIG_FILE);
            std::string body;
            Json::Value v;
            f.GetContent(&body);
            tqbcloud::JsonUtil::UnSerialize(body, &v);
            _hot_time = v["hot_time"].asInt();
            _server_port = v["server_port"].asInt64();
            _server_ip = v["server_ip"].asString();
            _url_prefix = v["url_prefix"].asString();
            _arc_suffix = v["arc_suffix"].asString();
            _pack_dir = v["pack_dir"].asString();
            _back_dir = v["back_dir"].asString();
            _manager_file = v["manager_file"].asString();
        }
        static Config *config_;
        static std::mutex mtx_;
        time_t _hot_time;
        int _server_port;
        std::string _server_ip;
        std::string _url_prefix;
        std::string _arc_suffix;
        std::string _pack_dir;
        std::string _back_dir;
        std::string _manager_file;

    public:
        static Config *getinstance()
        {
            if (config_ == NULL)
            {
                mtx_.lock();
                if (config_ == NULL)
                {
                    mtx_.unlock();
                    return new (Config);
                }
                mtx_.unlock();
            }
        }
        time_t Gethottime()
        {
            return _hot_time;
        }
        int GetServerPort()
        {
            return _server_port;
        }
        std::string GetServerIp()
        {
            return _server_ip;
        }
        std::string GetURLPrefix()
        {
            return _url_prefix;
        }
        std::string GetArcSuffix()
        {
            return _arc_suffix;
        }
        std::string GetPackDir()
        {
            return _pack_dir;
        }
        std::string GetBackDir()
        {
            return _back_dir;
        }
        std::string GetManagerFile()
        {
            return _manager_file;
        }
        // static Config *config_;
        // static std::mutex mtx_;
    };
    Config *Config::config_ = NULL;
    std::mutex Config::mtx_;
};
#endif